<template>
	<SearchForm :columns="formColumn" :defaultParam="list.params.courseScheduleFindPage" @search="search" @reset="handleReset" />
	<el-header>
		<div class="left-panel">
			<el-button icon="el-icon-download">导出</el-button>
			<!-- <el-button icon="el-icon-printer">打印</el-button> -->

			<el-checkbox-group v-model="date" style="margin-left:12px;">
				<el-checkbox
					v-for="item in dateList"
					:key="item.value"
					:label="item.value"
					>{{ item.label }}</el-checkbox
				>
			</el-checkbox-group>
		</div>
	</el-header>
	<el-main class="nopadding">
		<scTable
			ref="table"
			tableName="studentList"
			v-bind="list"
			row-key="id"
			stripe
		>
			<el-table-column type="selection" width="50"></el-table-column>
		</scTable>
	</el-main>
</template>

<script>
import SearchForm from "@/components/SearchForm/index.vue";
import { formColumn, column, dateList } from "./data";

export default {
	components: {
		SearchForm,
	},
	data() {
		const date = dateList.map((item) => item.value)

		return {
			formColumn,
			date,
			dateList: Object.freeze(dateList),
			list: {
				apiObj: this.$API.student.courseSchedule,
				params: {
					week: date,
					// classTime: [new Date().getTime(), new Date().getTime()]
				},
				column,
			},
		};
	},
	methods: {
		handleReset() {
			this.date = dateList.map((item) => item.value)
			this.search();
		},
		search(searchParams = {}) {
			console.log(searchParams);
			let params = {}
			if(searchParams) {
				const searchObj = JSON.parse(JSON.stringify(searchParams))
				if (searchObj.classTime) {
					searchObj.startTime = searchObj.classTime[0]
					searchObj.endTime = searchObj.classTime[1]
					delete(searchObj.classTime)
				}else{
					delete(searchObj.classTime)
				}
				params = Object.assign({}, searchObj, this.list.params)
			}else{
				params = Object.assign({}, this.list.params, {});
			}
      console.log(params);
			this.$refs.table.reload(params);

			// const params = Object.assign({}, this.list.params, searchParams, {
			// 	date: this.date,
			// });
			// this.$refs.table.reload(params);
		},
	},
};
</script>
